<?php
/**
 * @name IndexController
 * @author root
 * @desc 默认控制器
 * @see http://www.php.net/manual/en/class.yaf-controller-abstract.php
 */
class CashController extends Controller_Base {
	//后台首页
	public function indexAction() {
		$this->CashModel = new CashModel();
		$page = isset($_GET['page'])?$_GET['page']:1;
		$start = isset($_GET['start'])?$_GET['start']:"";

		$option1 = isset($_GET['option1'])?$_GET['option1']:"";
		$option2 = isset($_GET['option2'])?$_GET['option2']:"";
		$option="";
		$sqlstr="";
		if($option1&&$option2){
			$option="";
		}elseif($option1){
			$option="-1";
			$sqlstr="";
		}else if($option2){
			$sqlstr=" and admin_status<>-1";
		}else{
			$option="";
		}
		$end = isset($_GET['end'])?$_GET['end']:"";
		$username=isset($_GET['realname'])?$_GET['realname']:"";
		$where=array("datatime>"=>strtotime($start),"datatime<"=>strtotime($end),"realname like"=>"%$username%","admin_status"=>$option);

		$data = $this->CashModel->selectAsset($where,$page,20,$sqlstr);
		$count	    = $this->CashModel->selectCount($where,$sqlstr);
		$pages = new Pages($page,$count,20);
		$this->getView()->assign("page",$page);
		$this->getView()->assign("pages",$pages->getView());
		//分配变量
		$this->getView()->assign("data",$data);

	}

	//操作 拒绝 或通过
	public function doaddAction() {
		$this->CashModel = new CashModel();
		//print_r($_POST);exit();
		$xuanze = isset($_POST['xuanze'])?$_POST['xuanze']:1;
		$id= isset($_POST['id'])?$_POST['id']:0;
		$pingzheng=isset($_POST['pingzheng'])?$_POST['pingzheng']:"";
		$memo=isset($_POST['memo'])?$_POST['memo']:"";

		if($xuanze==1){
			$up = new Upload(array('json'=>false,'path'=>'/upload/','maxsize'=>'2000000','allowtype'=>array("gif", "png", "jpg","jpeg","php"),'israndname'=>true));
			//设置属性(返回类型是否json数据，上传的位置(支持创建文件夹)， 大小maxsize=2000000表示2M文件大小， 允许文件类型， 名是是否要随机生成)
			$result=$up -> upload("pz_img");
			if(isset($result['url'])&&$result['url']){
				$result=$this->CashModel->setCash(array('admin_status'=>1,'pz_img'=>$result['url']),array('asset_id'=>$id));
			}else{
				print_r($result);
				exit("图片上传失败~");
			}
			if(1){
				echo json_encode(array('data'=>'操作成功！'));
				header("location:$_SERVER[HTTP_REFERER]");
				exit();
			}


		}elseif($xuanze==2){
			$result=$this->CashModel->setCash(array('admin_status'=>2,'memo'=>$memo),array('asset_id'=>$id));
			if(1){
				echo json_encode(array('data'=>'操作成功！'));
				header("location:$_SERVER[HTTP_REFERER]");
				exit();
			}
		}else{
			exit();
		}




	}



}